package com.du;

import com.du.bean.Boss;
import com.du.bean.Car;
import com.du.bean.Color;
import com.du.bean.Yellow;
import com.du.config.MainConfigAutowired;
import com.du.config.MainConfigOfProfile;
import com.du.service.BookService;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;

/**
 * @author djg
 * @date 2020/11/23
 * @des
 */
public class IOCTestProfile {


    //切换运行时环境的方法
    //1、使用动态命令行参数 -Dspring.profiles.active=test
    //2、使用代码方式激活某种环境

    @Test
    public void test01() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //1、创建一个applicationContext
        //2、设置需要激活的环境
        applicationContext.getEnvironment().setActiveProfiles("test");
        //3、注册主配置类
        applicationContext.register(MainConfigOfProfile.class);
        //4、启动刷新容器
        applicationContext.refresh();

        String[] namesForType = applicationContext.getBeanNamesForType(DataSource.class);
        for (String name : namesForType) {
            System.out.println(name);
        }


        Yellow bean = applicationContext.getBean(Yellow.class);
        System.out.println(bean);
        applicationContext.close();

    }
}
